package com.lyf.baoxian.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.lyf.baoxian.R;
import com.lyf.baoxian.activity.AddCustomerActivity;
import com.lyf.baoxian.adapter.BaoDanAdapter;
import com.lyf.baoxian.adapter.CustomerAdaper;
import com.lyf.baoxian.bean.CustomerBaoDan;
import com.lyf.baoxian.bean.CustomerInfo;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘亚飞 on 2016/11/30.
 */

public class CustomerFragment extends BaseFragment implements View.OnClickListener {
   /* @Bind(R.id.table_title)
    ViewGroup table_title;*/

    @Bind(R.id.list_customer)
    ListView list_customer;

    @Bind(R.id.swip)
    SwipeRefreshLayout swip;

    //新增用户
    @Bind(R.id.bt_add_customer)
    TextView add_customer;

    private List<CustomerInfo> datas;

    @Override
    protected void afterCreate(Bundle savedInstanceState) {
        initData();
        /*LinearLayout ll = (LinearLayout) table_title.findViewById(R.id.ll_title_customer);
        ll.setBackgroundColor(Color.rgb(110, 33, 255));*/
        CustomerAdaper adapter = new CustomerAdaper(mActivity);
        adapter.setDatas(datas);
        list_customer.setAdapter(adapter);

        add_customer.setOnClickListener(this);

    }

    /**
     * 初始化数据
     */
    private void initData() {
        datas = new ArrayList<>();
        swip.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                SystemClock.sleep(300);
                swip.setRefreshing(false);
            }
        });
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));
        datas.add(new CustomerInfo("小明", "1344556668", "1338839222", "北京"));


    }

    @Override
    protected View addLayout(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_customer, null);
        return view;
    }

    @Override
    public void onDestroy() {
        ButterKnife.unbind(this);
        super.onDestroy();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_add_customer:
                Intent intent = new Intent(mActivity, AddCustomerActivity.class);
                startActivity(intent);
                break;
        }

    }
}
